<?php
$baseurl = JURI::base();

$time = time();
$date = date('Y-m-d',$time);

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select("id,title,created");
$query->from("#__content");
$query->where("state=1 AND created LIKE '%".$date."%'");
$query->order("ordering ASC, id DESC LIMIT 0,5");
$db->setQuery($query);
$lsNews = $db->loadObjectList();

if (count($lsNews)>=5){
?>
<div class="box">
	<div class="title">
		<div class="left"></div>
		<div class="center">Tin mới trong ngày</div>
		<div class="right"></div>
	</div>
	<div class="boxContent">
	<ul>
	<?php
	foreach ($lsNews as $new) {
		$link = JRoute::_("index.php?option=com_content&view=article&id=".$new->id);
		?>
		<li class="ls-news"><a href="<?php echo $link;?>"><?php echo $new->title;?></a></li>
		<?php
	}
	?>
	</ul>
	</div>
</div>
<?php }else{
	$query = $db->getQuery(true);
	$query->select("id,title,created");
	$query->from("#__content");
	$query->where("state=1");
	$query->order("created DESC, id DESC LIMIT 0,5");
	$db->setQuery($query);
	$lsNews2 = $db->loadObjectList();
?>
<div class="box">
	<div class="title">
		<div class="left"></div>
		<div class="center">Tin tức mới cập nhật</div>
		<div class="right"></div>
	</div>
	<div class="boxContent">
	<ul>
	<?php
	$nows = mktime(0,0,0,date("m"),date("d"),date("Y"));
	foreach ($lsNews2 as $new) {
		$link = JRoute::_("index.php?option=com_content&view=article&id=".$new->id);
		$ngay_nhap = mktime(0,0,0,unFormatdate($new->created,"m"),unFormatdate($new->created,"d"),unFormatdate($new->created,"Y"));				
		$days = ($nows - $ngay_nhap)/86400;
		if ($days>0){
			$class = ' class="ls-news none"';
		}else{
			$class = ' class="ls-news"';
		}
		?>
		<li<?php echo $class;?>>
			<a href="<?php echo $link;?>"><?php echo $new->title;?></a>
			<?php
			if ($days<=0){
				?>
				<img src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/images/newnew.gif" border="0" />
				<?php
			} 
			?>
		</li>
		<?php
	}
	?>
	</ul>
	</div>
</div>
<?php }?>